package com.ptmall.app.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jauker.widget.BadgeView;
import com.ptmall.app.R;


/**
 * Created by MacBook on 17/7/15.
 */


public class MeTitleAdapter extends BaseAdapter {
    private Context mContext;
    private int[] titleIcos;
    private String[] titleStrs;
    private boolean islist;
    public BadgeView mBadgeView;
    public MeTitleAdapter(Context context, int[] titleIcos, String[] titleStrs){
        this.mContext = context;
        this.titleIcos = titleIcos;
        this.titleStrs = titleStrs;
    }
    private String num;

    public void setmsgNum(String num){
        this.num = num;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return titleStrs.length;
    }

    @Override
    public Object getItem(int position) {
        return titleStrs[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView =
                    LayoutInflater.from(mContext).inflate(R.layout.metitle_item, parent, false);
            holder = new ViewHolder();
            holder.img = (ImageView) convertView.findViewById(R.id.img);
            holder.title = (TextView)convertView.findViewById(R.id.title);
            holder.viewLinearLayout = (LinearLayout) convertView.findViewById(R.id.viewLinearLayout);
            holder.rel = (RelativeLayout) convertView.findViewById(R.id.rel);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.img.setImageResource(titleIcos[position]);
        holder.title.setText(titleStrs[position]);
        if(titleStrs[position].equals("消息通知")){
            if(num==null||num.equals("0")){
                if(mBadgeView!=null){
                    mBadgeView.setVisibility(View.GONE);
                }
                return convertView;
            }
            mBadgeView = new BadgeView(parent.getContext());
            mBadgeView.setBackground(10, 0xFFFF0000);//色
            mBadgeView.setTargetView(holder.rel);
            mBadgeView.setText(num);
        }

        return convertView;
    }

    private class ViewHolder {
        private ImageView img;
        private TextView title;
        private LinearLayout viewLinearLayout;
        private RelativeLayout rel;
    }
}
